package net.wanho.controller;

import net.wanho.dto.StudentDTO;
import net.wanho.entity.Student;
import net.wanho.service.StudentService;
import net.wanho.vo.AjaxResult;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * Author：汤小洋
 * Date：2024-08-12 10:17
 * Description：<描述>
 */
@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping
    public AjaxResult add(@RequestBody Student stu){
        System.out.println(stu);
        studentService.add(stu);
        return AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Integer id){
        System.out.println(id);
        return AjaxResult.success();
    }

    @PutMapping
    public AjaxResult modify(Student stu){
        System.out.println(stu);
        return AjaxResult.success();
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Integer id){
        System.out.println(id);

        Student student = new Student(id, "张三",  18, "男", 180.7);
        return AjaxResult.success(student);
    }

    @GetMapping
    public AjaxResult getAll(){
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(1, "张三",  18, "男", 180.7));
        list.add(new Student(2, "李四",  19, "女", 180.7));
        list.add(new Student(3, "王五",  20, "男", 180.7));
        return AjaxResult.success(list);
    }

    @GetMapping("/query")
    public AjaxResult query(StudentDTO studentDTO){
        System.out.println(studentDTO);
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(1, "张三",  18, "男", 180.7));
        list.add(new Student(2, "李四",  19, "女", 180.7));
        return AjaxResult.success(list);
    }
}
